<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h2>我是阿giao</h2>
    <i>我是分支1</i>
    <strong>我是分支2</strong>
    <script>
        function SuperType(text) {
            text = text || '我是爸爸';
            this.superValue = text;
        }
        SuperType.prototype.say = function() {
            return this.superValue;
        }

        function SubType() {
            SuperType.call(this, '我是儿子');
            this.age = 10;
        }

        // object这个方法其实就是ES6中的Object.create()方法。object这个方法有个缺点，就是不能创建纯净的、没有原型对象的对象。
        function object(o) {
            const F = function() {};
            F.prototype = o;
            return new F();
        }
        // SubType的原型对象，需要改写为一个另对象，我们称之为C。这个C对象的__proto__指向了SuperType的原型对象。或者说这个对象C是SuperType的实例
        // SubType.prototype = Object.create(SuperType.prototype);
        // SubType.prototype.constructor = SubType;

        const SubTypePro = SubType.prototype;
        SubTypePro.__proto__ = SuperType.prototype;

        var subTypeInstance = new SubType();
        console.log(subTypeInstance);

        class SuperTypeClass {
            superValue = '';
            constructor(text) {
                this.superValue = text;
            }
            say() {
                return this.superValue;
            }
        }
        class SubTypeClass extends SuperTypeClass{
            age = 10;
            constructor() {
                super('我是儿子')
            }
        }

        var bb = new SubTypeClass();
        console.log(bb);
    </script>
</body>
</html>